package com.zx.scp.controller;

import java.net.URLDecoder;

import com.zx.map.service.model.*;
import com.zx.map.utils.MyBeanUtils;
import com.zx.scp.service.OutcomeService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/outcome")
public class OutcomeController {

    /**
     * log
     */
    private static Logger log = Logger.getLogger(OutcomeController.class);

    private static final boolean isTLTFront = Boolean.FALSE;

    @Autowired
    private OutcomeService outcomeService;

    @RequestMapping("/single")
    @ResponseBody
    public OutcomeResponse single(String params) {
        OutcomeResponse outcomeResponse = null;
        try {
        	log.debug("单笔出款请求："+params);
            OutcomeModel outcomeModel = MyBeanUtils.jsonToBean(params, OutcomeModel.class);
            //中文转码
            outcomeModel.setAccountName(URLDecoder.decode(outcomeModel.getAccountName(), "UTF-8"));
            return outcomeService.singleOutcome(outcomeModel, isTLTFront);
        } catch (Exception e) {
            outcomeResponse = new OutcomeResponse();
            log.info("系统内部异常", e);
            outcomeResponse.setReturnCode("9999");
            outcomeResponse.setErrMsg("系统内部异常");
            return outcomeResponse;
        }
    }


    @RequestMapping("/batch")
    @ResponseBody
    public BatchOutcomeResponse batch(String params) {
        BatchOutcomeResponse bor = null;
        try {
            BatchOutcomeModel batchOutcomeModel = MyBeanUtils.jsonToBean(params, BatchOutcomeModel.class);
            for(OutcomeModel oo : batchOutcomeModel.getOutcomeModelList()) {
            	//中文转码
            	oo.setAccountName(URLDecoder.decode(oo.getAccountName(), "UTF-8"));
            	oo.setProvince(URLDecoder.decode(oo.getProvince(), "UTF-8"));
            	oo.setCity(URLDecoder.decode(oo.getCity(), "UTF-8"));
            	oo.setBranchName(URLDecoder.decode(oo.getBranchName(), "UTF-8"));            	
            }
            return outcomeService.batchOutCome(batchOutcomeModel, isTLTFront);
        } catch (Exception e) {
            bor = new BatchOutcomeResponse();
            log.info("系统内部异常", e);
            bor.setReturnCode("9999");
            bor.setErrMsg("系统内部异常");
            return bor;
        }
    }


}
